﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace DHQGHN.PM0.Models.Admin
{
    public class RoleModel
    {
        public int RoleId { get; set; }

        //[Remote("CheckExistRoleName", "Role", ErrorMessage = "RoleCodeExist", HttpMethod = "POST", AdditionalFields = "RoleId , AppId")]
        [Required(AllowEmptyStrings = false, ErrorMessage = "Bạn chưa nhập tên vai trò")]
        [StringLength(100, ErrorMessage = "Độ dài tối đa 100 ký tự")]
        [Display(Name = "Tên vai trò")]
        public string RoleName { get; set; }

        //[Remote("CheckExistRoleCode", "Role", ErrorMessage = "RoleNameExist", HttpMethod = "POST", AdditionalFields = "RoleId , AppId")]
        [Required(AllowEmptyStrings = false, ErrorMessage = "Bạn chưa nhập mã vai trò")]
        [Display(Name = "Tên vai trò")]
        [StringLength(50, ErrorMessage = "Độ dài tối đa 50 ký tự")]
        public string RoleCode { get; set; }

        [Display(Name = "Mô tả")]
        [StringLength(500, ErrorMessage = "Độ dài tối đa 500 ký tự")]
        public string RoleDescription { get; set; }
                
        [Display(Name = "Tên ứng dụng")]
        [Range(1, int.MaxValue, ErrorMessageResourceName = "Error_HaventPutAppNameYet", ErrorMessageResourceType = typeof(Resources.Localization))]
        public int AppId { get; set; }

        public int IsActive { get; set; }
        public int RecordCount { get; set; }

        public const string FIELD_RECORD_COUNT = "RecordCount";
        #region Field list from DB
        public const string FIELD_ID = "RoleId";
        public const string FIELD_NAME = "RoleName";
        public const string FIELD_CODE = "RoleCode";
        public const string FIELD_DESCRIPTION = "RoleDescription";
        public const string FIELD_App_ID = "AppId";
        public const string FIELD_IS_ACTIVE = "IsActive";
        #endregion

        public RoleModel()
        {
            // TODO: Complete member initialization
        }

        public RoleModel(DAL.Models.Admin.RoleModel model)
        {
            // TODO: Complete member initialization
            RoleId = model.RoleId;
            RoleCode = model.RoleCode;
            RoleName = model.RoleName;
            RoleDescription = model.RoleDescription;
            AppId = model.AppId;
            RecordCount = model.RecordCount;
        }


        internal DAL.Models.Admin.RoleModel toDALModel()
        {
            DAL.Models.Admin.RoleModel model = new DAL.Models.Admin.RoleModel
            {
                RoleId = RoleId,
                RoleCode = RoleCode,
                RoleName = RoleName,
                RoleDescription = RoleDescription,
                AppId = AppId,
                RecordCount = RecordCount
            };
            return model;
        }
    }
}